﻿package core.display {
	
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import core.net.socket.CmdHandler;
	import flash.events.Event;
	import core.events.CmdEvent;
	import core.net.socket.cmd.GetBarCodeCmd;
	import core.dialog.DialogBluetoothDiscovery;
	import core.dialog.DialogBluetooth;
	import core.User;
	
	
	public class BtnBar extends SimpleButton {
		
		
		
		public function BtnBar() {
			
			this.addEventListener(Event.ADDED_TO_STAGE,onInit);
			this.addEventListener(Event.REMOVED_FROM_STAGE,onRemove);
		}
		
		private function onInit(e:Event):void {
			this.removeEventListener(Event.ADDED_TO_STAGE,onInit);
			this.addEventListener(MouseEvent.CLICK,onClick);
			
			
			//初始化自动连接一次
			//this.onClick(null);
		}
		
		private function onRemove(e:Event):void {
			this.removeEventListener(MouseEvent.CLICK,onClick);
			
		}
		
		private function onClick(e:MouseEvent):void {
			if(User.deviceAddress == null || User.deviceAddress == "" || User.deviceAddress == "0")
			{
				var dlg1:DialogBluetoothDiscovery = new DialogBluetoothDiscovery();
					this.stage.addChild(dlg1);
			}
			else
			{
				var dlg2:DialogBluetooth = new DialogBluetooth(User.deviceAddress);
					this.stage.addChild(dlg2);
			}
		}
		
	}
	
}
